package model.comparisons;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import model.IComparison;

public class Comparison6 implements IComparison {

	private List<Integer> arraylist = new ArrayList<Integer>();
	private List<Integer> linkedlist = new LinkedList<Integer>();
	private boolean isactive;
	private float[] times = new float[2];
	private int N;

	@Override
	public void setN(int N) {
		this.N = N;

	}

	@Override
	public void setActive(boolean isactive) {
		this.isactive = isactive;
	}

	@Override
	public float[] getTime() {
		if (isactive) {

			int[] x = new int[N];
			for (int i = 0; i < N; i++) {
				x[i] = (int) (Math.random() * 1000);
			}

			for (int i = 0; i < N; i++) {
				arraylist.add(i, x[i]);
				System.out.println(x[i]);
			}

			for (int i = 0; i < N; i++) {
				linkedlist.add(i, x[i]);
			}

			int cerca = Collections.max(arraylist);
			System.out.println(cerca);
			// primo
			long startTime = System.nanoTime();

			arraylist.indexOf(cerca);

			long tmp = System.nanoTime() - startTime;
			System.out.println(tmp);
			times[0] = ((float) (System.nanoTime() - startTime)) / 1000000;
			// secondo
			long startTime2 = System.nanoTime();

			linkedlist.indexOf(cerca);

			times[1] = ((float) (System.nanoTime() - startTime2)) / 1000000;

			//System.out.println(times[0] + " " + times[1]);// test
			return times;
		}

		return new float[] { 1, 1 };
	}

}
